IF OBJECT_ID('dbo.fnGetPersonName') IS NOT NULL
BEGIN
    DROP FUNCTION dbo.fnGetPersonName
    IF OBJECT_ID('dbo.fnGetPersonName') IS NOT NULL
        PRINT '<<< FAILED DROPPING FUNCTION dbo.fnGetPersonName >>>'
    ELSE
        PRINT '<<< DROPPED FUNCTION dbo.fnGetPersonName >>>'
END
go

-- =======================================================================
-- Function Name: dbo.fnGetPersonName()
--
-- Author:      Kevin Cashman, Parallax Consulting LLC
--
-- Create date: 8/1/2007
--
-- Description: Returns The Fully Qualified name for a given PersonId
--             
--
-- Parameters:  @PersonId = INT
--              
-- Returns:     VARCHAR(50) 
--
-- SampleCall:
-- SELECT @PersonName = fnGetPersonName ( 1234 )
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 8/1/07      KC        Created
-- 8/29/07     KC        Added MI
--
-- =======================================================================
CREATE FUNCTION dbo.fnGetPersonName(
     @PersonId INT
)
     RETURNS VARCHAR(50)
AS
BEGIN
     DECLARE   @PersonName    VARCHAR(50)

     SELECT    @PersonName = RTRIM(P.LastName) + ', ' + RTRIM(P.FirstName) + RTRIM(IsNull(' ' + P.MiddleName,''))
     FROM      dbo.AdmPerson P 
     WHERE     P.Id = @PersonId

     RETURN @PersonName

END
go
IF OBJECT_ID('dbo.fnGetPersonName') IS NOT NULL
    PRINT '<<< CREATED FUNCTION dbo.fnGetPersonName >>>'
ELSE
    PRINT '<<< FAILED CREATING FUNCTION dbo.fnGetPersonName >>>'
go
